package cc.booku.owlbox.TestPage;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;
import java.util.concurrent.Executors;

import cc.booku.owlbox.R;

class CustomizeDomestic_A extends RecyclerView.Adapter<CustomizeDomestic_A.ItemHolder> {


    private ArrayList<CustomizeDomestic_C> customize_Domestic_cArrayList;
    private int id;
    private Context context;
    //private LayoutInflater inflater;
    ImageView vod_pic = null;

    public CustomizeDomestic_A(Context context, ArrayList<CustomizeDomestic_C> customize_Domestic_cArrayList) {
        this.customize_Domestic_cArrayList = customize_Domestic_cArrayList;
        this.context = context;
        // inflater = LayoutInflater.from(context);
    }

    @Override
    public int getItemCount() {
        return customize_Domestic_cArrayList.size();
    }

    @Override
    public void onViewRecycled(ItemHolder itemHolder) {
        super.onViewRecycled(itemHolder);
    }

    @NonNull
    @Override
    public ItemHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        //创建
        //找到item
        View view = LayoutInflater.from(context).inflate(R.layout.test_item, viewGroup, false);
        //将布局设置给holder
        return new ItemHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ItemHolder itemHolder, int position) {

        //itemHolder.vod_pic.setImageDrawable(context.getDrawable(R.drawable.ic_image));

//为imageView设置Tag,内容是该imageView等待加载的图片url

        //将数据设置到item上
        CustomizeDomestic_C bean = customize_Domestic_cArrayList.get(position);
//        itemHolder.text.setText(bean.getVod_actor());
//        itemHolder.image.setImageResource(bean.getImage());

        itemHolder.vod_name.setText(bean.getVod_name().toString());//对象为空
        itemHolder.vod_class.setText(bean.getVod_class().toString());
        itemHolder.vod_score.setText(bean.getVod_score().toString());
        itemHolder.vod_add_time.setText(bean.getVod_add_time().toString());
        itemHolder.vod_value_add.setText(bean.getVod_value_add().toString());
        itemHolder.vod_play_url.setText(bean.getVod_play_url().toString());
        itemHolder.vod_pic_url.setText(bean.getVod_pic_url().toString());
        //itemHolder.vod_pic.setTag(bean.getVod_pic());
        LoadImage(vod_pic, bean.getVod_pic());


    }

//    @Override
//    public int getItemCount() {
//        if (this.customize_Domestic_cArrayList != null) {
//            return customize_Domestic_cArrayList.size();
//        }
//        return 0;
//    }

    public class ItemHolder extends RecyclerView.ViewHolder {

        TextView vod_score = null;
        TextView vod_name = null;
        TextView vod_class = null;
        TextView vod_add_time = null;
        ImageView vod_pic = null;
        TextView vod_play_url = null;
        TextView vod_pic_url = null;
        TextView vod_value_add = null;

        public ItemHolder(@NonNull View itemView) {
            super(itemView);
//            text = itemView.findViewById(R.id.text);
//            image = itemView.findViewById(R.id.image);

            vod_score = (TextView) itemView.findViewById(R.id.vod_score);
            vod_name = (TextView) itemView.findViewById(R.id.vod_name);
            vod_class = (TextView) itemView.findViewById(R.id.vod_class);
            vod_add_time = (TextView) itemView.findViewById(R.id.vod_add_time);
            vod_value_add = (TextView) itemView.findViewById(R.id.vod_value_add);
            vod_play_url = (TextView) itemView.findViewById(R.id.vod_play_url);
            vod_pic_url = (TextView) itemView.findViewById(R.id.vod_pic_url);
            vod_pic = (ImageView) itemView.findViewById(R.id.vod_pic);
        }
    }


    private void LoadImage(ImageView img, String path) {
        //ImageLoader.loadImage(image_url, filmclass.getPimg());
        //Log.d("LoadImage", "img=====" + path);
        AsyncTaskImageLoad async = new AsyncTaskImageLoad(img);
        async.executeOnExecutor(Executors.newCachedThreadPool(), path);//快的多
        //async.execute(path);
    }


//
//
//        public CustomizeDomestic_A(int item, Context context, ArrayList<CustomizeDomestic_C> customize_Domestic_cArrayList) {
//            this.customize_Domestic_cArrayList = customize_Domestic_cArrayList;
//            this.context = context;
//            this.id = item;
//            inflater = LayoutInflater.from(context);
//
//        }
//
//        @Override
//        public int getCount() {
//            return customize_Domestic_cArrayList.size();
//        }
//
//        @Override
//        public Object getItem(int i) {
//            return customize_Domestic_cArrayList.get(i);
//        }
//
//        @Override
//        public long getItemId(int i) {
//            return i;
//        }
//
//
//        @SuppressLint("WrongConstant")
//        @Override
//
//        public View getView(final int i, View view, ViewGroup viewGroup) {
//
//
//            TextView vod_score = null;
//            TextView vod_name = null;
//            TextView vod_class = null;
//            TextView vod_add_time = null;
//            ImageView vod_pic = null;
//            TextView vod_play_url = null;
//            TextView vod_pic_url = null;
//            TextView vod_value_add = null;
//
//            CustomizeDomestic_A.ViewHolder viewHolder;
//            if (view == null) {
//                view = inflater.inflate(id, null);
//
//                vod_score = (TextView) view.findViewById(R.id.vod_score);
//                vod_name = (TextView) view.findViewById(R.id.vod_name);
//                vod_class = (TextView) view.findViewById(R.id.vod_class);
//                vod_add_time = (TextView) view.findViewById(R.id.vod_add_time);
//                vod_value_add = (TextView) view.findViewById(R.id.vod_value_add);
//                vod_play_url = (TextView) view.findViewById(R.id.vod_play_url);
//                vod_pic_url = (TextView) view.findViewById(R.id.vod_pic_url);
//                vod_pic = (ImageView) view.findViewById(R.id.vod_pic);
//
//
//                view.setTag(new ViewHolder(vod_score, vod_name, vod_class, vod_add_time, vod_value_add, vod_play_url,vod_pic_url, vod_pic));
//            } else {
//                CustomizeDomestic_A.ViewHolder viewHolder1 = (CustomizeDomestic_A.ViewHolder) view.getTag(); // 重新获取ViewHolder
//                vod_score = viewHolder1.vod_score;
//                vod_class = viewHolder1.vod_class;
//                vod_name = viewHolder1.vod_name;
//                vod_add_time = viewHolder1.vod_add_time;
//                vod_value_add = viewHolder1.vod_value_add;
//                vod_play_url = viewHolder1.vod_play_url;
//                vod_pic_url = viewHolder1.vod_pic_url;
//
//            }
//            CustomizeDomestic_C cc = (CustomizeDomestic_C) customize_Domestic_cArrayList.get(i); // 获取当前项的实例
//
//            //video_public_classListc
//            vod_name.setText(cc.getVod_name().toString());//对象为空
//            vod_class.setText(cc.getVod_class().toString());
//            vod_score.setText(cc.getVod_score().toString());
//            vod_add_time.setText(cc.getVod_add_time().toString());
//            vod_value_add.setText(cc.getVod_value_add().toString());
//            vod_play_url.setText(cc.getVod_play_url().toString());
//            vod_pic_url.setText(cc.getVod_pic_url().toString());
//            LoadImage(vod_pic, cc.getVod_pic());
//
//
//            return view;
//
//        }
//
//
//        private void LoadImage(ImageView img, String path) {
//            //ImageLoader.loadImage(image_url, filmclass.getPimg());
//            //Log.d("LoadImage", "img=====" + path);
//            AsyncTaskImageLoad async = new AsyncTaskImageLoad(img);
//            async.executeOnExecutor(Executors.newCachedThreadPool(), path);//快的多
//            //async.execute(path);
//        }
//
//
//        private final class ViewHolder {
//            TextView vod_score = null;
//            TextView vod_name = null;
//            TextView vod_class = null;
//            TextView vod_add_time = null;
//            ImageView vod_pic = null;
//            TextView vod_play_url = null;
//            TextView vod_pic_url = null;
//            TextView vod_value_add = null;
//
//
//            public ViewHolder(TextView vod_score, TextView vod_name, TextView vod_class, TextView vod_add_time, TextView vod_value_add, TextView vod_play_url,TextView vod_pic_url,  ImageView vod_pic) {
//                this.vod_class = vod_class;
//                this.vod_score = vod_score;
//                this.vod_name = vod_name;
//                this.vod_add_time = vod_add_time;
//                this.vod_play_url = vod_play_url;
//                this.vod_pic_url = vod_pic_url;
//                this.vod_value_add = vod_value_add;
//                this.vod_pic = vod_pic;
//
//            }
//
//        }

    private AdapterView.OnItemClickListener onItemClickListener;//声明一下这个接口

    //提供setter方法
    public void setOnItemClickListener(AdapterView.OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

}